package com.hotel.controller;

import com.hotel.pojo.Admin;
import com.hotel.service.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/admin")

public class AdminController {

    @Autowired
            AdminServiceImpl adminService;

    @RequestMapping("/login")
    public ModelAndView login(String username, Integer password){

        Admin admin=adminService.findAdmin(username,password );
        ModelAndView mv = new ModelAndView();
        if(admin!=null){
            if(password.equals(admin.getPassword())){
                mv.setViewName("index");
            }else {
                mv.addObject("msg", "密码错误，请重试");
                mv.setViewName("error");
            }
            return mv;
        }
        mv.addObject("msg", "账号异常，请重试");
        mv.setViewName("error");
        return mv;
    }

    @RequestMapping("/updatePwd")
    public String update(Admin admin){
        adminService.updatePwd(admin);
        return "suc_a";
    }
}
